package com.huang.controller;

import com.huang.pojo.Attractions;
import com.huang.pojo.PageResult;
import com.huang.service.AttractionsService;
import com.huang.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/attractions")
public class AttractionsController {
    @Autowired
    AttractionsService attractionsService;
//景点信息查询
@GetMapping("/atrList")
    public SysResult getAttractionsList(PageResult pageResult){
    //判断用户是否传入了参数
      // System.out.println(pageResult.getQuery());
    String query=pageResult.getQuery();

    if (query.equals("")||query==null) {
        pageResult=attractionsService.getAtrlist(pageResult);
        return SysResult.success(pageResult);
    }
    pageResult=attractionsService.getAtrlist1(pageResult);
    return SysResult.success(pageResult);
    }
    //景点信息添加
    @PostMapping("/addstr")
    public SysResult addstr(@RequestBody Attractions attractions){
       // System.out.println(attractions);
        String name=attractions.getName();
        String atrinfo = attractions.getAtrinfo();
        String atrlevel = attractions.getAtrlevel();
        int num= attractions.getNum();
        int price= attractions.getPrice();
        Boolean status = attractions.getStatus();
         attractionsService.addStr( name,atrinfo,atrlevel,num,price,status);
         return SysResult.success();


    }
    //改变景点信息状态
    @PutMapping("/updatestatus")
    public SysResult updateItemStatus(@RequestBody Attractions attractions){

    int id=attractions.getId();
    boolean status=attractions.getStatus();
    attractionsService.update(id,status);

    return SysResult.success();
    }

    @PutMapping("/updateinfo")
    public SysResult updateinfo(@RequestBody Attractions attractions){
       int id=attractions.getId();
        String name=attractions.getName();
        String atrinfo = attractions.getAtrinfo();
        String atrlevel = attractions.getAtrlevel();
        int num= attractions.getNum();
        int price= attractions.getPrice();
        Boolean status = attractions.getStatus();
        attractionsService.updateatr(id, name,atrinfo,atrlevel,num,price,status);

       return SysResult.success();
    }

    //根据id删除景点信息
    @DeleteMapping("/deleteStrById")
    public SysResult deleteStrById( Integer id){
    attractionsService.deleteStrById(id);
    return SysResult.success();
    }
    //用户获取景点信息的数据
    @GetMapping("/atrListl")
    public SysResult getAtrListl(){
     List<Attractions>  list=attractionsService.getAtrListl();
    return SysResult.success(list);
    }
}
